<!DOCTYPE html>
<html>
<head>
    <title>添加</title>
</head>
<link rel="stylesheet" href="/static/layui/css/layui.css" />
<body>
<form class="layui-form" id="rend-add"  action="" lay-filter="add">
    <div class="layui-form-item">
        <label class="layui-form-label">房屋名称</label>
        <div class="layui-input-inline  layui-col-md4">
            <select name="h_id" id = "h_id">
                <option value=""></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">租户名称</label>
        <div class="layui-input-inline  layui-col-md4">
            <select name="l_id"  id = "l_id">
                <option value=""></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">缴纳金额：</label>
        <div class="layui-input-inline">
            <input type="text" name="r_money" id="r_money" required  lay-verify="required" placeholder="请输入缴纳金额" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">缴费时间：</label>
        <div class="layui-input-inline">
            <input type="text" name="r_time" id="r_time" required  lay-verify="required" placeholder="请输入缴费时间" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注：</label>
        <div class="layui-input-inline layui-col-md4">
            <textarea placeholder="请输入内容" name="r_remark"   class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>

<script src="/static/js/jquery-3.3.1.js"></script>
<script src="/static/layui/layui.js"></script>
<script>
    layui.use(['form','laydate'], function() {
        var form = layui.form;
        $.ajax({
            url: "/RendServlet?action=toAddHouse",
            type: "post",
            // data:{},
            dataType: "json",
            success: function (res) {
                console.log(res)
                $.each(res.date, function (i, obj) {
                    console.log(obj);
                    $("#h_id").append('<option value="' + obj.h_id + '">' + +obj.h_area + obj.h_estate + obj.h_unitNumber + '</option>');
                });
                form.render('select'); //刷新select选择框渲染
            }
        });
        $.ajax({
            url: "/RendServlet?action=toAddLess",
            type: "post",
            // data:{},
            dataType: "json",
            success: function (res) {
                console.log(res)
                $.each(res.date, function (i, obj) {
                    console.log(obj);
                    $("#l_id").append('<option value="' + obj.l_id + '">' + obj.l_name + '</option>')
                });
                form.render('select'); //刷新select选择框渲染
            }
        });
    });
    //Demo
    layui.use(['form','laydate'], function(){
        var form = layui.form,laydate = layui.laydate;
        laydate.render({
            elem: '#r_time'
        });
        //监听提交
        form.on('submit(formDemo)', function(data){
            var data1 = form.val("add");
            $.ajax({
                url:'/RendServlet?action=add',
                type:"post",
                dataType:"json",
                data:data1,
                success:function (da) {
                    if (da.code == 200) {
                        layer.alert("添加成功！", function () {
                            // window.parent.location.reload();//刷新父页面
                            // parent.layer.close(layer.index);//关闭弹出层
                            parent.layer.closeAll();
                        });
                    } else {
                        layer.msg("添加失败！");
                    }
                }
            });
            return false;
        });

    });
</script>
</html>